package com.gang.mars.basic.generictype.demo9.annotation;

import java.lang.reflect.AnnotatedElement;

/**
 * @Author：gang.chen
 * @Date：2023/6/27 9:41
 */
public abstract class GangAnnotationsScanner {

    /**
     * 重点留意：C,R 由GangAnnotationsProcessor接口实例来固定
     *
     * @param context; Object -> String
     * @param source ; null
     * @param searchStrategy; null
     * @param processor ; GangMergedAnnotationFinder
     *
     * return GangMergedAnnotation<GangAnnotation>
     * */
    static <C, R> R scan(C context, AnnotatedElement source, Object searchStrategy, GangAnnotationsProcessor<C, R> processor)
    {
        R result= process(context, source, searchStrategy, processor);

        return result;
    }

    /**
     * @param context; Object -> String
     * @param source; null
     * @param searchStrategy; null
     * @param processor; GangMergedAnnotationFinder
     *
     * return GangMergedAnnotation<GangAnnotation>
     * */
    private static<C, R> R process(C context, AnnotatedElement source, Object searchStrategy, GangAnnotationsProcessor<C, R> processor)
    {
        if (true)
        {
            return processClass(context, null,searchStrategy, processor);
        }
        if (false){
            //TODO
        }
        return null;
    }

    /**
     * @param context; Object -> String
     * @param source; Class
     * @param searchStrategy; null
     * @param processor; GangMergedAnnotationFinder
     *
     * return GangMergedAnnotation<GangAnnotation>
     * */
    private static <C, R> R processClass(C context, Class<?> source, Object searchStrategy, GangAnnotationsProcessor<C, R> processor)
    {
        // switch

        return processClassInheritedAnnotations(context, source, searchStrategy, processor);
    }

    /**
     * @param context; Object -> String
     * @param source ; Class -> null
     * @param searchStrategy; null
     * @param processor; GangMergedAnnotationFinder
     *
     * return GangMergedAnnotation<GangAnnotation>
     * */
    private static <C, R> R processClassInheritedAnnotations(C context, Class<?> source, Object searchStrategy, GangAnnotationsProcessor<C, R> processor)
    {
        try
        {
            if (true)
            {
                return processElement(context, null, processor);
            }
            //TODO

        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @param context; Object -> String
     * @param source; Class -> null
     * @param processor; GangMergedAnnotationFinder
     *
     * */
    private static<C, R> R processElement(C context, AnnotatedElement source, GangAnnotationsProcessor<C,R> processor)
    {
        R result = processor.doWithAnnotations(context, 0, null, null);

        return result;
    }
}
